#!/bin/bash
#
# Copyright (C) 2000-2025 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Test the .json command
#
TestName="jlist-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-confs

start_test

sed -i "s/catalog = all/catalog = all, events/" $conf/bacula-dir.conf

cat <<EOF > $tmp/bconcmds
label volume=TestVolume001 storage=File1 pool=File drive=0 slot=0
run job=BackupClient1 level=Full yes
run job=BackupClient1 level=Full yes
run job=BackupClient1 level=Full yes
wait
messages
gui on
@$out $tmp/log1.log
.jlist events
@$out $tmp/log2.log
.jlist events limit=1
@$out $tmp/log3.log
.jlist jobs
@$out $tmp/log4.log
.jlist joblog jobid=1
EOF

run_bacula

for i in 1 2 3 4; do
    grep '\[' $tmp/log$i.log > $tmp/log$i.json
    $bperl -e "check_json('$tmp/log$i.json')"
    if [ $? != 0 ]; then
        print_debug "ERROR: Unable to validate $tmp/log$i.log"
        estat=1
    fi
done

stop_bacula

end_test
